/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package TransportLayer;

import DataModel.INotaryPolicy;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.omg.CORBA.PolicyListHelper;

/**
 *
 * @author Tomasz Nowak
 */
class TaskChecker implements Runnable
{

	int idx;
	List<NotaryResponse> resultArray;
	List<Future<NotaryResponse>> results;
	INotaryPolicy policy;

	public TaskChecker( int idx, List<NotaryResponse> resultArray, List<Future<NotaryResponse>> results, INotaryPolicy policy )
	{
		this.idx = idx;
		this.resultArray = resultArray;
		this.results = results;
		this.policy = policy;
	}

	@Override
	public void run()
	{
		try
		{
			resultArray.add(idx, results.get(idx).get(policy.getOperationTimeout(), TimeUnit.MILLISECONDS));
		}
		catch ( TimeoutException e )
		{
			resultArray.add(idx, null);
		}
		catch ( InterruptedException ex )
		{
			Logger.getLogger(ServiceClient.class.getName()).log(Level.SEVERE, null, ex);
		}
		catch ( ExecutionException ex )
		{
			Logger.getLogger(ServiceClient.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

}
